/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.coordinador;

import DBMS.DataBaseManager;
import clases.Aspirante;
import clases.Institucion;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author tamerdark
 */
public class Modificar extends DispatchAction {
    
    public ActionForward update(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Aspirante a = (Aspirante) form;
        request.setAttribute("instituciones", Institucion.getAll());
        DataBaseManager dbms = DataBaseManager.getInstance();
        boolean modificado = dbms.modificarAspirante(a);
        if (modificado) {
            a.setMensaje("Aspirante modificado con exito");
            return mapping.findForward("success");
        } else {
            a.setMensaje("Error al modificar el aspirante");
            return mapping.findForward("failure");
        }
    }
    
    public ActionForward populate(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        request.setAttribute("instituciones", Institucion.getAll());
        return mapping.findForward("page");
    }
}
